import TreeTraversal.TreeNode;

public class diameterOfBinaryTree1 {
    int nums;
    public int diameterOfBinaryTree(TreeNode root) {
        a(root);
        return nums-1;
    }
    public int a(TreeNode root){
        if(root == null){
            return 0;
        }
        int L = a(root.left);
        int R = a(root.right);
        nums = Math.max(nums,L+R+1);
        return Math.max(L,R)+1;
    }
}
